﻿Imports MeoTom.Core.BLL
Imports MeoTom.Core

Partial Public Class ArticleUpdate
    Inherits UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim objArticle As New Articles()
        Dim objTag As New Tags()
        Dim objComment As New Comments()
        Dim util2 As New Utilities.Common()
        Try
            If Request.QueryString("action") = "Delete" Then
                Dim previousPage As String = ""
                If Request.QueryString.ToString = vbNullString Then
                    previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
                Else
                    previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
                End If
                util2.ValidateLogin(previousPage)

                objArticle.ArticlesId = Int32.Parse(Request.QueryString("ID"))
                objArticle.GetByEdit()

                objTag.ArticleID = objArticle.ArticlesId
                objTag.UpdateTotalArticle()

                objComment.ArticleId = objArticle.ArticlesId
                objComment.DeleteByArticle()

                util2.DeleteFile(Configs.ArticleFile & "ListFile\" & objArticle.CreatedDate.Year.ToString() & "\" & objArticle.CreatedDate.Month.ToString() & "\" & objArticle.CreatedDate.Day.ToString() & "\" & objArticle.ArticlesId & ".xml")

                objArticle.Delete()
                objArticle.WriteTop10View()
                objArticle.WriteTop10Last()
                objArticle.WriteTopStory()
                objTag.GetDefaultTag(0)
                Response.Redirect("/mt-inside/ArticleUpdate.aspx", False)
            ElseIf Request.QueryString("action") = "Edit" Then
                Dim control As New UI.Control
                control = Page.LoadControl("~/Control/ArticleEdit.ascx")
                pnlControl.Controls.Add(control)
            Else
                Dim control As New UI.Control
                control = Page.LoadControl("~/Control/ArticleList.ascx")
                pnlControl.Controls.Add(control)
            End If
        Catch ex As Exception
            'lg.WriteLog(ex.Message, Request.Url.ToString)
        Finally
            objArticle = Nothing
            objTag = Nothing
            objComment = Nothing
        End Try
    End Sub
End Class